<?php

/**
 * Created by PhpStorm.
 * User: qiliping
 * Date: 2017/6/17
 * Time: 16:52
 */
class User_withdrawal_model extends CI_Model
{
  function get_withdrawl_by_user($user_id,$limit=0,$offset=10){
    $this->db->trans_start();
    $sql = "select SQL_CALC_FOUND_ROWS w.* from {$this->db->dbprefix}user_withdrawal w  where w.user_id = $user_id  order by id desc limit $limit,$offset";
    $result = $this->db->query($sql)->result_array();
    $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();

    $this->db->trans_complete();

    return array("total_count" => $row_num['row_num'], "result" => $result);
  }

  function get_amount_for_withdrawl($user_id){
    $sql = "SELECT SUM(amount) as amount from {$this->db->dbprefix}user_withdrawal where user_id = $user_id and status =0";
    $result = $this->db->query($sql)->row_array();
    if($result['amount']){
      return $result['amount'];
    }else {
      return 0;
    }
  }
}
